package com.example.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import org.apache.ibatis.type.Alias;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Alias("ArticleStatusEnum")
public enum ArticleStatusEnum {
    Deleted(0, "已删除"),
    Draft(10, "未发布"),
    Published(20, "已发布"),
    Reverted(30, "已撤回");

    private int value;
    private String description;

    private ArticleStatusEnum(int value, String description) {
        this.value = value;
        this.description = description;
    }

    @JsonValue
    public int getValue() {
        return this.value;
    }

    public String getDescription() {
        return this.description;
    }

    public static List<Map<String, Object>> getDescriptionList() {
        List<Map<String, Object>> result = new ArrayList<>();
        ArticleStatusEnum[] values = ArticleStatusEnum.values();
        for (ArticleStatusEnum item : values) {
            Map<String, Object> keyValuePair = new HashMap<>();
            keyValuePair.put("code", item.toString());
            keyValuePair.put("value", item.getValue());
            keyValuePair.put("description", item.getDescription());
            result.add(keyValuePair);
        }

        return result;
    }
}
